package com.mp.netty.manage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mp.core.utils.Utils;
import com.mp.core.utils.common.NettyCommon;
import com.mp.core.utils.netty.UserChannelRel;
import com.mp.enums.ActionEnum;
import com.mp.enums.ToSendEnum;
import com.mp.pojo.NO.BinDingChannelNO;
import com.mp.pojo.NO.WebsiteFlyRecordNO;
import com.mp.pojo.VO.WebsiteFlyRecordVO;
import com.mp.service.WebsiteFlyRecordService;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *@description:
 *@author: Ace
 *@create: 2019-09-05 10:57
 */
@Component
public class WebsiteFlyRecordManage {

    @Autowired
    private NettyCommon nettyCommon;

    @Autowired
    private WebsiteFlyRecordService websiteFlyRecordService;

    /**
     * 飞单记录
     * @param flyRecord
     */
    public void flyRecord(WebsiteFlyRecordNO flyRecord) {
        if (Utils.isNull(new Object[]{flyRecord.getWebsiteUserId(),flyRecord.getCode(),flyRecord.getSize(),flyRecord.getCurrent()})){
            return;
        }
        //查询飞单记录分页
        IPage<WebsiteFlyRecordVO> page = websiteFlyRecordService.pageWebsiteFlyRecord(flyRecord);
        nettyCommon.wsWrite200(flyRecord.getWebsiteUserId(),page,ActionEnum.FLY_RECORD,ToSendEnum.TO_RECEIVER);

    }

    /**
     * 绑定Channel
     * @param binDingChannel
     * @param channel
     */
    public void binDingChannel(BinDingChannelNO binDingChannel, Channel channel) {
        UserChannelRel.put(binDingChannel.getWebsiteUserId(),channel);
        nettyCommon.wsSimpleWrite200(channel, ActionEnum.BINDINGCHANNEL, "发送成功", ToSendEnum.TO_RECEIVER);
    }
}
